package com.qd.admin.api;

import com.cdqidi.dto.ApiResult;
import com.cdqidi.dto.ApiResultWrapper;
import com.qd.common.panda.domain.entity.api.UnpaidAmountDTO;
import com.qd.panda.mq.charge.ExecutorService;
import com.qd.panda.service.plate.PlateService;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import javax.validation.constraints.NotBlank;

/**
 * API_对外接口
 * @author sjk
 */
@RestController
@RequestMapping("/api")
@Slf4j
@AllArgsConstructor
@Validated
public class ApiController {
    private final PlateService plateService;
    private final ExecutorService executorService;

    /**
     * 判断车牌号是否存在
     *
     * @param plateNumber 车牌号
     * @return true or false
     */
    @GetMapping(value = "/existsPlateNumber")
    public ApiResultWrapper<Object> register(@Valid @NotBlank(message = "车牌号不能为空") String plateNumber) {
        return ApiResult.success(plateService.isExistsById(plateNumber));
    }

    /**
     * 计算剩余未支付费用
     *
     * @param parkId      停车场ID
     * @param plateNumber 车牌号
     */
    @GetMapping(value = "/getUnpaidAmount")
    public UnpaidAmountDTO getUnpaidAmount(@Valid @NotBlank(message = "停车场ID不能为空") String parkId, @NotBlank(message = "车牌号不能为空") String plateNumber) {
        return executorService.getUnpaidAmount(parkId, plateNumber);
    }

//    /**
//     * 测试
//     */
//    @RequestMapping(value = "/test", method = RequestMethod.POST)
//    @SneakyThrows
//    public ApiResultWrapper<Object> register(@Valid @RequestBody CarParkDTO carParkDTO) {
//        log.debug("test: {}", objectMapper.writeValueAsString(carParkDTO));
//        return ApiResult.success();
//    }
}